


        const fs =require('fs');
        
        
        let persons = fs.readFileSync('persons.json','utf8')
        persons = JSON.parse( persons )
        //  persons = JSON.stringify( user )
        //现有
        let user = { username:"xiaoming1",password:"333" }
           let tt=persons.some(function(item){
              return item.username===user.username;
            });
            if(tt){
                console.log('注册的账户已经存在');
                
            }else{
                persons .push(user);
            }
            console.log(persons);
           //注册原理：如果persons中没有对应的用户，则把user追加到persons末尾
           persons = JSON.stringify( persons )
           fs.writeFileSync('persons.json', persons,{flag:'w' })